package org.app
package dao

import models.UserModel

import scala.collection.mutable.ListBuffer

class UserDAO {
  // 加载所有的用户
  def loadUsers(): ListBuffer[UserModel] = {
    val users = new ListBuffer[UserModel]()
    val source = scala.io.Source.fromFile("users.txt")
    for(line <- source.getLines()){
      val Array(username, password, role) = line.split(",")
      // 实例化一个用户，保存到List
      users += UserModel(username, password, role)
    }
    // 关闭连接
    source.close()
    users
  }
}
